Conditions | 10 |
Total Lines | 41 |
Code Lines | 33 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Complex classes like index.ts ➔ main often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
1 | import { files } from "../files" |
||
16 | |||
17 | async function main() { |
||
18 | const templateRoot = `${__dirname}/template/` |
||
19 | , outputRoot = `${__dirname}/output/` |
||
20 | |||
21 | for (const id_ in files) { |
||
22 | const { |
||
23 | path, |
||
24 | } = files[id_] |
||
25 | |||
26 | if (!path) |
||
27 | continue |
||
28 | |||
29 | const append = appenderSync(`${outputRoot}${path}`) |
||
30 | |||
31 | for await (const line of createLineReader(`${templateRoot}${path}`)) { |
||
32 | const templ = templateLine<"id"|"value"|"prefix"|"postfix">(line) |
||
33 | |||
34 | if (!templ) { |
||
35 | await append(line, "\n") |
||
36 | continue |
||
37 | } |
||
38 | |||
39 | const { |
||
40 | indentation, |
||
41 | id, |
||
42 | value, |
||
43 | prefix, |
||
44 | postfix |
||
45 | } = templ |
||
46 | , valueStr = value ? `=${value}` : "" |
||
47 | |||
48 | await append( |
||
49 | arr2line(indentation, prefix, `ENV_${id}${valueStr}`, postfix) |
||
50 | ) |
||
51 | |||
52 | for (const key in files) { |
||
53 | if (key === id) |
||
54 | continue |
||
55 | await append( |
||
56 | arr2line(indentation, prefix, `${id}_CATCH_${key}${value ? `=\${ENV_${key}}` : ""}`, postfix) |
||
57 | ) |
||
62 |